import Vue from 'vue'
import App from './App'
import store from "./store/index"
// import Vant from 'vant'; // 全局引入
import Mydialog from "./components/dialog.vue"
import promptDialogBox from "./components/promptDialogBox.vue"
import VConsole from 'vconsole'
import './index.css'
import {
	Button,
	DropdownMenu,
	DropdownItem,
	Dialog,
	Overlay,
	Area,
	Popup,
	Picker,
	Calendar,
	Field,
	Toast,
	Uploader,
	Icon,
	ActionSheet,
	SwipeCell,
	Cell,
	ImagePreview,
	Divider,
	IndexBar,
	IndexAnchor,
	Search,
	Loading,
	Swipe,
	SwipeItem,
	Lazyload,
	DatetimePicker,
	Progress,
	Circle 
} from 'vant'; // 按需引入
import uView from "uview-ui";
import VueCropper from 'vue-cropper'
import VBar from '@/components/VBar.vue'
import VRadio from '@/components/VRadio.vue'
import PickerView from '@/components/PickerView.vue'
import keyWord from '@/components/keyWord.vue'
import dragButton from '@/components/dragButton.vue'
import VIcon from '@/components/VIcon.vue'
import Festival from '@/components/Festival.vue'
Vue.component('VIcon', VIcon)
Vue.component('VBar', VBar)
Vue.component('VRadio', VRadio)
Vue.component('PickerView', PickerView)
Vue.component('keyWord', keyWord)
Vue.component('dragButton', dragButton)
Vue.component('Festival', Festival)

Vue.config.productionTip = false

Vue.use(DatetimePicker).use(Button).use(DropdownMenu).use(IndexBar).use(Loading).use(Search).use(IndexAnchor).use(Divider).use(ActionSheet)
	.use(DropdownItem).use(ImagePreview).use(Cell).use(SwipeCell).use(Icon).use(Dialog).use(Overlay).use(Area).use(Popup).use(
		Picker).use(Calendar).use(Field).use(Toast).use(Uploader).use(Swipe).use(SwipeItem).use(Lazyload);
Vue.component("promptDialogBox", promptDialogBox).component("Mydialog", Mydialog)
Vue.use(Progress);
Vue.use(Circle);
// Vue.component("dialog", dialog)

Vue.use(uView);

Vue.use(VueCropper)

// const vConsole = new VConsole()
import {
	post,
	get
} from "./util/api.js";
// 引入token
import {
	getToken,
	setToken,
	removeToken
} from "./util/saveToken.js"

// 图片的路径
import {
	imgUrl
} from './util/api'

//百度商桥
import baiduData from "./util/baiduSq.json"

// 全局需要使用的方法
import {
	changeText,
	matcheHTML
} from "./util/changefont/changekeyWord.js"
App.mpType = 'app'
Vue.prototype.$store = store
const app = new Vue({
	store,
	...App
})
Vue.prototype.$changeText = changeText
Vue.prototype.$matcheHTML = matcheHTML
Vue.prototype.$post = post
Vue.prototype.$get = get
Vue.prototype.$getToken = getToken
Vue.prototype.$setToken = setToken
Vue.prototype.$removeToken = removeToken
Vue.prototype.$imgUrl = imgUrl

let wx = require('jweixin-module');
Vue.prototype.$wx = wx
Vue.config.ignoredElements.push('wx-open-launch-weapp')

app.$mount()

let url = window.location.host
let bdPath = ''
// console.log(555555555, url)
baiduData.list.map((item, index) => {
	if (item.key === url) {
		bdPath = item.value
	}
})
if (!bdPath) {
	bdPath = 'https://hm.baidu.com/hm.js?5d2db21b15eb503b2f7d64fe58eeb4d7'
}
console.log('bdPath', bdPath)


document.write('<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"><\/script>');
document.write('<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"><\/script>');

document.addEventListener('UniAppJSBridgeReady', function () {
	uni.webView.getEnv((res) => {
		if (!res.miniprogram) {
			// eslint-disable-next-line
			var _hmt = _hmt || [];
			// eslint-disable-next-line
			setTimeout(function () {
				window._hmt = _hmt; // 修改为window 全局变量
				(function () {
					var hm = document.createElement("script");


					hm.src = bdPath;
					var s = document.getElementsByTagName("script")[0];
					s.parentNode.insertBefore(hm, s);
				})();
			}, 5000)
		}
	})
})

// function locationHashChanged(){
// 	alert(222222)

// }
window.addEventListener('hashchange', () => {
	//console.log(location.hash.split('=')[1])
	let pairs = location.hash.substr(1).split('&').map(function (pair) {
		var kv = pair.split('=', 2);
		return [decodeURIComponent(kv[0]), kv.length === 2 ? decodeURIComponent(kv[1]) : null];
	})
	pairs.map((v) => {
		if (v[0] == "token") {
			console.log("save token", v[1])
			uni.setStorageSync("Mtoken", v[1]);
		}
		// if(v[0]=='openid'){
		// 	console.log("save openid",v[1])
		// 	uni.setStorageSync("openId",v[1]);
		// }
	})
	// setTimeout(()=>{
	// 	window.history.go(-1);
	//   }, 0);
}, false)
//indow.onhashchange = locationHashChanged;